/**
 * <p>Copyright (c) 2017 深圳市鹏途交通科技有限公司 </p>
 * <p>		    All right reserved. 		     </p>
 * <p>项目名称 ： 	 深圳公路信息资源整合及国省检日常化监管管理        </p>
 * <p>创建者   :	詹春贤 
 * <p>描   述  :   路网服务-应急抢通的数据管理的控制器  </p>
 * <p>最后修改 : $: 2017年8月30日-下午4:21:37 v 1.0.0	 Administrator   $ </p>
 * 
*/

package com.pengtu.gsj.controller.lwfw;

import javax.servlet.http.HttpServletRequest;



import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.lwfw.EmergRepair;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.lwfw.EmergRepairService;
import com.pengtu.gsj.utils.MathsUtils;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

/**
 * 
 * EmergRepairController
 * 
 * 2017年8月30日 下午4:21:37
 * 
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("emergRepair")
public class EmergRepairController extends DefaultBaseController{
	
	@Autowired
	private EmergRepairService emergRepairService;

	/**
	 * 加载
	 * @param id
	 * @return
	 */
	@ModelAttribute
	public EmergRepair load(String id){
		EmergRepair emergRepair;
		if(StringUtils.isNotEmpty(id)){
			emergRepair = emergRepairService.getEmergRepairById(id);
		}else{
			emergRepair = new EmergRepair();
		}
		return emergRepair;
	}
	
	
	/**
	 * 页面跳转
	 * @return
	 */
	@Token(save = true)
	@RequestMapping("listInfo")
	public String showLisfInfo() {
		return "lwfw/emergRepair_list";
	}
	
	
	@ResponseBody
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	public Page<EmergRepair> getEmergRepairList(Page<EmergRepair> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("year");
			page.setOrder(Page.ASC);
		}
		page = emergRepairService.findEmergRepair(page,queryFilter);
		return page;
	}
	
	/**
	 * saveEmergRepair:
	 * 适用: 保存应急抢通的数据
	 * @param emergRepair
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@Token(remove = true)
	@RequestMapping(value = "save", method=RequestMethod.POST)
	public boolean saveEmergRepair(@ModelAttribute EmergRepair emergRepair){
		//自动计算恢复百分比 = 上报数 / 恢复数 *100
		emergRepair.setRatio(MathsUtils.divDouble(emergRepair.getRestoreNum() * 100, emergRepair.getReportNum(), 2));
		emergRepairService.saveEmergRepair(emergRepair);
		return true;
	}
	
	
	/**
	 * showEmergRepair:
	 * 适用: 展示应急抢通页面
	 * @param emergRepair
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody    
	@RequestMapping(value="show")
	public EmergRepair showEmergRepair (@ModelAttribute EmergRepair emergRepair){
		return emergRepair;
	}
	
	/**
	 * delateInfoManagement:
	 * 适用: 删除应急抢通的数据
	 * @param emergRepair
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value="delete")
	public boolean delateInfoManagement(@ModelAttribute EmergRepair emergRepair){
		emergRepairService.delateEmergRepair(emergRepair);
		return true;
	}
	
	/**
	 * checkYear:
	 * 适用:应急抢通数据管理中控制验证录入数据的年份唯一
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value="checkYear", produces="application/json;charset=utf-8")
	public boolean checkYear() {
		String year = SpringMvcUtils.getParameter("year");
		String id = SpringMvcUtils.getParameter("id");
		return emergRepairService.checkYear(year, id);
	}
}
